*Recoding ZA1487: Includes also all observations from ZA1486

use "Data\ZA1487\ZA1487.dta" , clear

*Support for democracy
gen $idea_democracy			= V25

*Support for liberal democracy
	*not included in dataset
	
*Satisfaction with democracy
*FEHLERHAFTE VARIABLE!
*gen $satisfaction_democracy = V442

gen $satisfaction_democracy = V27

*Efficacy
gen $politicians_takecare = V289
gen $ego_politicscomplicated = V288


*define missing values
*recode missing values 
	
*Standardize range from 0 to 1; higher values indicate higher support for democracy
replace $idea_democracy =  (6-$idea_democracy) / 5  if !missing($idea_democracy)
replace $satisfaction_democracy = (6-$satisfaction_democracy) / 5 if !missing($satisfaction_democracy)
replace $politicians_takecare = ($politicians_takecare - 1)/3  if !missing($politicians_takecare)
replace $ego_politicscomplicated = (4 - $ego_politicscomplicated) / 3  if !missing($ego_politicscomplicated)

*Sociodemographic Controls
gen		$gender 			= V294-1

gen 	$age				= V298

gen 	$education			= V299
replace $education 			= 0 if $education <= 5 | $education == 7  // still at school, None, Hautpschulabschluss, Mittlere Reife, Fachhochschulreife, other  = 0
replace $education 			= 1 if $education == 6					  // Abitur = 1

gen $eastwest 				= 0										  // no respondents from East Germany 	

*Party ID
*Did R lean towards  a left, right or other party?
*1: right, (CDU/CSU, FDP, AfD), 0: left (Left/PDS, Greens, SPD), -1: other
gen $partyid_category		= 1 	if inlist(V445, 1, 2, 3, 6)
replace $partyid_category	= 0 	if inlist(V445, 4, 5)
replace $partyid_category	= -1 	if inlist(V445, 7, 8, 9, 10, 12)


*Party Vote
*Did R lean towards  a left, right or other party?
*1: right, (CDU/CSU, FDP, AfD), 0: left (Left/PDS, Greens, SPD), -1: other
gen $partyvote_category		= 1 	if inlist(V18, 1, 3)
replace $partyvote_category	= 0 	if inlist(V18, 2, 4)
replace $partyvote_category	= -1 	if inlist(V18, 5, 6, 7, 8, 9)


*Meta variables
gen 	$dataset 			= ""
replace $dataset		 	= "ZA1487"	if V1 == 1770				//projektkennzeichnung 1770 = ZA1487		
replace $dataset		 	= "ZA1486"	if V1 == 6181				//projektkennzeichnung 6181 = ZA1486
gen 	$year 				= 1900+V461								//V461 == abbreviated year

*check
tab $idea_democracy V25, m  //check
tab $satisfaction_democracy V27, m
tab $gender V294, m
tab $age V298, m
tab $education V299, m



*weight
gen weight = V465													//weight for years 1985 and 1986; assumed to be equally distributed in both years

*Save recode dataset
keep $idea_democracy $satisfaction_democracy $politicians_takecare $ego_politicscomplicated $gender $age $education $eastwest $dataset $year  weight	$partyid_category	$partyvote_category	
save ZA1487_recoded.dta, replace

